Skip to content

fix(bigquery-jdbc): bound BigDecimal scale in epoch-decimal timestamp parsing - #15218

Merged
Neenu1995 merged 1 commit into
mainfrom
fix/b-584839496-bound-epoch-bigdecimal-scale
Nov 25, 2026
Merged

Neenu1995 merged 1 commit into
mainfrom
fix/b-584839496-bound-epoch-bigdecimal-scale

Conversation

@Neenu1995

Copy link
Copy Markdown
Contributor

Bug: b/584839496

The Issue

BigQueryTemporalUtility.parseEpochDecimalToInstant and BigQueryTemporalUtility.formatTimestampStringFromEpochDecimal called new BigDecimal(epochDecimal).setScale(..., RoundingMode.DOWN) without bounding input length or exponent magnitude. Coercing a STRING or JSON column containing a large-exponent scientific-notation value (such as "1e100000000", "1e2147483648", or "12345678901234567890e-100000000") via ResultSet.getTimestamp or ResultSet.getObject, or formatting out-of-range epoch-decimal strings in TIMESTAMP(12) / RANGE<TIMESTAMP>, triggered unbounded BigInteger.bigTenToThe expansion, causing uninterruptible CPU stalls and uncaught OutOfMemoryError (or unchecked DateTimeException on 17-digit out-of-range epoch seconds).

The Fix

  • Added BigQueryTemporalUtility.parseScaledEpochDecimal to reject strings longer than 128 characters, short-circuit zero (signum() == 0) and sub-unit magnitudes (integerDigits <= -scale) to BigDecimal.ZERO.setScale(scale), and reject integer magnitudes exceeding 17 digits (Instant.MIN..Instant.MAX width, computed in long arithmetic to prevent 32-bit int overflow) before calling BigDecimal.setScale.
  • Wrapped LocalDateTime.ofEpochSecond in formatTimestampStringFromEpochDecimal to catch DateTimeException and rethrow BigQueryJdbcException.
  • Added unit regression tests in BigQueryTemporalUtilityTest covering extreme positive exponents, extreme sub-unit/zero exponents, and overlong inputs.

@Neenu1995
Neenu1995 requested review from a team as code owners November 25, 2026 00:38

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces safe parsing of epoch decimal strings in BigQueryTemporalUtility to prevent potential performance issues or Denial of Service (DoS) vulnerabilities caused by extremely large or long decimal values. It adds a helper method parseScaledEpochDecimal that enforces length limits, validates the number of integer digits, and handles extreme sub-unit exponents efficiently. Additionally, it wraps LocalDateTime.ofEpochSecond in a try-catch block to handle DateTimeException gracefully. Corresponding unit tests have been added to verify these edge cases. I have no feedback to provide as there are no review comments.

@Neenu1995 Neenu1995 changed the title [WIP] fix(bigquery-jdbc): bound BigDecimal scale in epoch-decimal timestamp parsing fix(bigquery-jdbc): bound BigDecimal scale in epoch-decimal timestamp parsing Nov 25, 2026
@Neenu1995
Neenu1995 merged commit 25eebb6 into main Nov 25, 2026
193 checks passed
@Neenu1995
Neenu1995 deleted the fix/b-584839496-bound-epoch-bigdecimal-scale branch November 25, 2026 18:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants